<?php

abstract class Loader
{

    protected static $path = [];

    public static function register($prefix, $path)
    {
        self::$path[trim($prefix, '\\')] = str_replace('\\', '/', $path) . '/';
    }

    public static function load($namespace)
    {
        $namespace = str_replace('\\', '/', $namespace);;
        $prefix = explode('/', $namespace)[0];

        // class fount !
        if(array_key_exists($prefix, self::$path))
        {
            $path = self::$path[$prefix] . $namespace . '.php';

            // already loaded ?
            if(!class_exists($path, false))
            {
                require $path;
                return true;
            }
        }

        return false;
    }

    public static function path($key)
    {
        if(!array_key_exists($key, self::$path))
            die('Loader ['.$key.'] does not exists.');

        return self::$path[$key];
    }

}